<template>
    <zk-table ref="zkTable" :data="tableData" :columns="columns" :stripe="true" :border="true" :show-header="true" :show-row-hover="true" :tree-type="true" :is-fold="false" :expand-type="false" children-prop="children" :selection-type="false">
      <template slot="operation" slot-scope="scope">
        <div>
          <i-switch v-model="scope.row.check" @on-change="(value)=>{change(value,scope.row)}" :value="scope.row" size="small"/>
        </div>
      </template>
    </zk-table>
</template>

<script>


export default {
  props: ["tableData", "selectData"],//接收来自父组件的数据
  data() {
    return {
      columns: [
        {label: '功能名称',prop: 'name',minWidth: 200},
        // {label: '权限标识',prop: 'menuAuthority',minWidth: '200px',},
        {label: '授权',width:'100px',prop: '',align: "center",type: 'template',template: 'operation',}
      ],
    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态

  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态

  },
  methods: {//执行的方法
    change(data, data1) {
      var that = this;
      var obj = {roleId: that.selectData.roleId, menuId: data1.id}
      if (data) {//开启
        that.axios.post(that.apiUrl.webApi + "/system/role/systemRoleAllocateMenu", obj).then(res => {
            if (!!res) {

            }
          }).catch(err => {
          console.log("失败", err)
        })
      } else {//关闭
        that.axios.post(that.apiUrl.webApi + "/system/role/systemRoleRemoveMenu", obj).then(res => {
            if (!!res) {

            }
          }).catch(err => {
          console.log("失败", err)
        })
      }
    }
  },
  watch: {//监听

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style>

</style>
